package com.hspedu.list_;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
 * @Author Stringzhua
 * @Date 2024/3/10 20:57
 * description:
 */
public class ListExercise {
    @SuppressWarnings("all")
    public static void main(String[] args) {
        List list = new ArrayList();
        for (int i = 0; i < 12; i++) {
            list.add("hello"+i);
        }
        System.out.println("list = " + list);
        //在2号位置插入"韩顺平教育"
        list.add(1,"韩顺平教育");
        System.out.println("list = " + list);

        //获得第五个元素
        System.out.println(list.get(4));

        //删除第六个元素
        list.remove(5);
        System.out.println("list = " + list);

        //修改第七个元素
        list.set(6,"爪爪");
        System.out.println("list = " + list);

        //迭代器遍历集合
        Iterator iterator = list.iterator();
        while (iterator.hasNext()) {
            Object next =  iterator.next();
            System.out.println("next = " + next);
        }
//        增强for循环
        for (Object o :list) {
            System.out.println("o = " + o);
        }

    }
}
